/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package comparacion;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

public class ConnectSQLServer {
    
int cont=0;
public ArrayList<objetoSql> lista = new ArrayList();   
objetoSql o = new objetoSql(null,null,null);
            
                                    
    public ArrayList<objetoSql> dbConnect(String db_connect_string,String db_userid,
            String db_password) {
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection conn = DriverManager.getConnection
                    (db_connect_string, db_userid, db_password);
            System.out.println("Conectado a la base de datos!");
            Statement statement = conn.createStatement();
                 
            ResultSet rs = null;                 
            
            String queryString = "SELECT * FROM secureway..Vehiculos,secureway..Empresas WHERE "
                    + "Vehi_Empr_id = Empr_id and Vehi_Empr_id != 2914 and Vehi_Empr_id != 2185 and Vehi_Empr_id != 2609";
                    
            rs = statement.executeQuery(queryString);                           //ejecuto la consulta
            objetoSql o = new objetoSql(null,null,null);
        //    objetoSql b = new objetoSql(null,null,null);
        //    lista.add(b);
            while(rs.next()){
                lista.add(new objetoSql(rs.getString("Empr_nombre"),rs.getString("vehi_textid"),rs.getString("vehi_color")));
           }
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
                }
                System.out.println("Tamaño de la lista: " + lista.size());
                  
        for(objetoSql o : lista){
            System.out.println(o.getEmpr_nombre() + " " + o.getVehi_color() + " " + o.getVehi_textid());         
              }
        System.out.println("Fin del programa.");
        
     return lista;   
    }
    
    
    
}